#pragma once

#include "SocketBase.h"

class Socket;

/////////////////////////////////////////////////
/// \class ServerSocket
///
/// \brief Provide server socket operations
///
/// Provide server socket operations for socket listen
/// and accept a connect-in TCP connection.
/////////////////////////////////////////////////
class ServerSocket : public SocketBase
{
public:
	ServerSocket();
	virtual ~ServerSocket();

	/////////////////////////////////////////////////
	/// \fn int Init()
	/// \return Error code of this operation, zero as success.
	///
	/// Initialize the server socket.
	/// A server socket must be initialized before doing other operations.
	/////////////////////////////////////////////////
	int Init();

	/////////////////////////////////////////////////
	/// \fn int Bind(int port)
	/// \return Error code of this operation, zero as success.
	///
	/// Bind the server socket to a certain port of local network interfaces.
	/////////////////////////////////////////////////
	int Bind(int port);

	/////////////////////////////////////////////////
	/// \fn int Listen()
	/// \return Error code of this operation, zero as success.
	///
	/// Listen for connect-in TCP connection.
	/// The bind operation have to be done before this operation.
	///
	/// @see Bind
	/////////////////////////////////////////////////
	int Listen();

	/////////////////////////////////////////////////
	/// \fn int Accept(Socket& sock)
	/// \return Error code of this operation, zero as success.
	/// \param [out] sock The new accepted connect-in TCP connection socket.
	///
	/// Accept a connect-in TCP connection.
	/// The bind operation have to be done before this operation.
	/////////////////////////////////////////////////
	int Accept(Socket& sock);
};
